package binarySearch;

/**
 * 旋转数组 利用二分法求解
 * @author le
 */
public class RotateArrayBinarySearch
{
    public static void main(String[] args)
    {
        int[] arr = {4,5,6,7,8,9,1,2,3};

        int left = 0;
        int right = arr.length-1;
        int tar = 6;

        while(left < right){
            int mid = left + (right - left)/2;
            if (tar == arr[mid]){
                System.out.println(arr[mid]);
            }
            if (arr[mid] > arr[left]){
                if (arr[left] < tar && tar < arr[mid]){
                    right = mid - 1;
                }else{
                    left = mid + 1;
                }
            }else{
                if (arr[right] > tar && tar > arr[mid]){
                    left = mid + 1;
                }else{
                    right = mid - 1;
                }
            }

        }

    }
}
